#ifndef _STATIC_STATE_H_
#define _STATIC_STATE_H_
#include "PCH.h"
#include "DeRenderResource.h"

namespace DeviousRenderer
{


template<typename InitializerType, typename StateType>
class TStaticState
{
public:
	StateType		GetState()
	{
		static DeStaticStateResource Resource;
		return Resource.m_State;
	}
private:

	class DeStaticStateResource : public DeRenderResource
	{
	public:
		StateType		m_State;

		DeStaticStateResource()
		{
			Initialize();
		}
		~DeStaticStateResource()
		{
			Release();
		}
		virtual void InitResource()
		{
			m_State = InitializerType::CreateState();
		}
		virtual void ReleaseResource()
		{
			m_State.SafeRelease();
		}
	};
	
};

//---------- RasterizerState -------------
template<ERasterizerCullMode FillMode=FM_SOLID, ERasterizerCullMode CullMode=CM_NONE, bool bEnableLineAA=false,bool bEnableMSAA=false>
class TStaticRasterizerState : public TStaticState<TStaticRasterizerState<FillMode, CullMode, bEnableLineAA, bEnableMSAA>, DeRasterizerStatePtr>
{
public:
	static DeRasterizerStatePtr CreateState()
	{
		DeRasterizerDescription desc = {FillMode, CullMode, 0, 0, bEnableLineAA, bEnableMSAA};
		return DeRenderDevice::CreateRasterizerState(&desc);
	}
};

}
#endif//_STATIC_STATE_H_